package practice;

import java.io.File;
import java.util.Scanner;


/**
 * Created with IntelliJ IDEA.
 * Description:
 * Author:  LiuTao
 * Version: 1.0
 * Date:    2024-04-01  21:00
 */
public class Demo {
    public static void main(String[] args) {
        Scanner scanner = new Scanner(System.in);
        System.out.println("请输入查找的路径：");
        String rootPath = scanner.next();

        File rootFile = new File(rootPath);
        if(!rootFile.isDirectory()) {
            System.out.println("您输入的路径有误");
            return;
        }

        System.out.println("请输入查找的文件名：");
        String name = scanner.next();

        scanDir(rootFile,name);
    }

    private static void scanDir(File rootFile, String name) {
        File[] files = rootFile.listFiles();
        if(files == null) {
            return;
        }
        for(File f : files) {
            if(f.isDirectory()) {
                scanDir(f,name);
            } else if (f.getName().equals(name)) {
                System.out.println("找到文件" + f.getName() + "路径为：" + f.getAbsolutePath());
            }
        }
    }

}
